package com.firesrc.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jodd.db.DbThreadSession;
import jodd.db.oom.DbOomQuery;

/**
 * Servlet implementation class ViewMailSendState
 */
public class ViewMailSendState extends SuperServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ViewMailSendState() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		response.setCharacterEncoding("GBK");
		response.setContentType("text/html; charset=gb2312");
		DbThreadSession dbThreadSession = new DbThreadSession(cp);

		String sendSql = "select count(id)  from record   where mailstate='1'";
		DbOomQuery q = new DbOomQuery(sendSql);
		long sendCount = q.executeCount();

		String allSql = "select count(id)  from record where mail is not null";
		DbOomQuery all = new DbOomQuery(allSql);
		long allCount = all.executeCountAndClose();

		response.getWriter().println("总共记录是<" + allCount + ">个 <br/>");
		response.getWriter().println("已经发送的是<" + sendCount + ">个 <br/>");
		response.getWriter().println("还没有发送邮件的记录有<" + (allCount - sendCount) + ">个 <br/>");
		dbThreadSession.closeSession();
		request.setAttribute("allCount", allCount);
		request.setAttribute("sendCount", sendCount);
		request.getRequestDispatcher("mailSendState.jsp").forward(request, response);
	}

}
